home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume5 / bsd.getut.2 < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  3.1 KB

  1. Path: xanth!mcnc!rutgers!ukma!cwjcc!hal!ncoast!allbery
  2. From: paul@devon.UUCP (Paul Sutcliffe Jr.)
  3. Newsgroups: comp.sources.misc
  4. Subject: v05i060: A more complete getut emulation
  5. Message-ID: <8811100436.AA12349@devon.UUCP>
  6. Date: 26 Nov 88 23:12:26 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: paul@devon.UUCP (Paul Sutcliffe Jr.)
  9. Organization: Devon Computer Services, Lancaster, PA
  10. Lines: 115
  11. Approved: allbery@ncoast.UUCP
  12.  
  13. Posting-number: Volume 5, Issue 60
  14. Submitted-by: "Paul Sutcliffe Jr." <paul@devon.UUCP>
  15. Archive-name: bsd.getut.2
  16.  
  17. +---------
  18. | Posting-number: Volume 5, Issue 37
  19. | Submitted-by: "Jeff Beadles" <jeff@tekcsc.mkt.tek.com>
  20. | Archive-name: bsd.getut
  21. | [I take it this was redirected.  Note that it won't help you compile s5finger
  22. | on a non-System-V system:  getutline() isn't here.  ++bsa]
  23. +---------
  24.  
  25. Okay, so you need a getutline()?  Here is the complete getutent
  26. emulation that I use here at devon.  You may post this in c.s.m. if you
  27. feel it useful to the net at large (given they've already seen bsd.getut).
  28.  
  29. - paul
  30.  
  31. ----- 8< ---------- 8< ---------- 8< ---------- 8< ---------- 8< -----
  32. #! /bin/sh
  33. # This is a shell archive, meaning:
  34. # 1. Remove everything above the #! /bin/sh line.
  35. # 2. Save the resulting text in a file.
  36. # 3. Execute the file with /bin/sh (not csh) to create the files:
  37. #    getutent.c
  38. # This archive created: Wed Nov  9 23:34:29 1988
  39. export PATH; PATH=/bin:$PATH
  40. echo shar: extracting "'getutent.c'" '(1324 characters)'
  41. if test -f 'getutent.c'
  42. then
  43.     echo shar: will not over-write existing file "'getutent.c'"
  44. else
  45. sed 's/^X//' << \SHAR_EOF > 'getutent.c'
  46. X/**
  47. X **  Simulate SysV getutent(3) calls, as best as can be done in
  48. X **  a System III environment, at least.
  49. X **
  50. X **  Author: Paul Sutcliffe, Jr.  <paul@devon.uucp>
  51. X **
  52. X **  I hereby place this in the public domain.
  53. X **  No warranties expressed or implied.
  54. X **/
  55. X
  56. X#include <stdio.h>
  57. X#include <string.h>
  58. X#include <sys/types.h>
  59. X#include <utmp.h>
  60. X
  61. Xstatic char *utmpfil = "/etc/utmp";    /* default utmp file */
  62. Xstatic FILE *ufp = NULL;        /* file pointer to utmp file */
  63. X                    /* NULL = no utmp file open  */
  64. Xstatic struct utmp ut;            /* buffer for utmp record */
  65. X
  66. Xstruct utmp *getutent(), *getutline();
  67. Xvoid pututline(), setutent(), endutent(), utmpname();
  68. X
  69. Xstruct utmp *
  70. Xgetutent()
  71. X{
  72. X    FILE *fopen();
  73. X
  74. X    if (ufp == NULL) {
  75. X        if ((ufp = fopen(utmpfil, "r+")) == NULL) {
  76. X            return((struct utmp *)NULL);
  77. X        }
  78. X    }
  79. X    do {
  80. X        if (fread((char *)&ut, sizeof(ut), 1, ufp) != 1) {
  81. X            return((struct utmp *)NULL);
  82. X        }
  83. X    } while (ut.ut_name[0] == 0);        /* valid entry? */
  84. X
  85. X    return(&ut);
  86. X}
  87. X
  88. Xstruct utmp *
  89. Xgetutline(line)
  90. Xstruct utmp *line;
  91. X{
  92. X    do {
  93. X        if (strcmp(ut.ut_line, line->ut_line) == 0) {
  94. X            return(&ut);
  95. X        }
  96. X    } while (getutent() != (struct utmp *)NULL);
  97. X
  98. X    return((struct utmp *)NULL);
  99. X}
  100. X
  101. Xvoid
  102. Xsetutent()
  103. X{
  104. X    if (ufp != NULL) rewind(ufp);
  105. X}
  106. X    
  107. Xvoid
  108. Xendutent()
  109. X{
  110. X    if (ufp != NULL) fclose(ufp);
  111. X}
  112. X
  113. Xvoid
  114. Xutmpname(file)
  115. Xchar *file;
  116. X{
  117. X    utmpfil = file;
  118. X}
  119. SHAR_EOF
  120. if test 1324 -ne "`wc -c < 'getutent.c'`"
  121. then
  122.     echo shar: error transmitting "'getutent.c'" '(should have been 1324 characters)'
  123. fi
  124. fi # end of overwriting check
  125. #    End of shell archive
  126. exit 0
  127.